//
//  JBWMainMeViewController.m
//  JBWDSK
//
//  Created by 崔志伟 on 2018/7/30.
//  Copyright © 2018年 崔志伟. All rights reserved.
//

#import "JBWMainMeViewController.h"
#import "JBWReviseNameViewController.h"
#import "JBWRevisePassWordViewController.h"
#import "JBWBindingPhoneViewController.h"
#import "JBWRealNameAuthenticationViewController.h"
#import "JBWSDKInstance.h"

#import "JBWMainNavView.h"
#import "TJWBMeNameTableViewCell.h"
#import "JBWMePassWordTableViewCell.h"
#import "JBWMeVersionTableViewCell.h"


@interface JBWMainMeViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UIView  * bottomView ;
@end

@implementation JBWMainMeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    self.mainNavView.isHideBackBtn = YES;
    self.mainNavView.backTitle = @"我的";
    UITableView *tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.contenView.bounds.size.width, self.contenView.bounds.size.height-70)];
    tabelView.backgroundColor = [UIColor clearColor] ;
    tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tabelView.delegate = self;
    tabelView.dataSource = self;
    [tabelView registerClass:[TJWBMeNameTableViewCell class] forCellReuseIdentifier:@"TJWBMeNameTableViewCell"];
    [tabelView registerClass:[JBWMePassWordTableViewCell class] forCellReuseIdentifier:@"JBWMePassWordTableViewCell"];
    [tabelView registerClass:[JBWMeVersionTableViewCell class] forCellReuseIdentifier:@"JBWMeVersionTableViewCell"];
    [self.contenView addSubview:tabelView];
    self.bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, self.contenView.bounds.size.height-70, self.contenView.bounds.size.width, 70)];
    
    UILabel *lognAccountLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,0, 150, 70)];
    lognAccountLabel.font = [UIFont systemFontOfSize:13];
    lognAccountLabel.textColor = [UIColor grayColor];
    lognAccountLabel.text = @"已登录 18688497608";
    [self.bottomView addSubview:lognAccountLabel];
    
    UIButton *switchAccountBtn = [[UIButton alloc]initWithFrame:CGRectMake(150, 0, 80, 70)];
    [switchAccountBtn setTitle:@"切换账号" forState:UIControlStateNormal];
    [switchAccountBtn addTarget:self action:@selector(switchAccountBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [switchAccountBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    switchAccountBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.bottomView addSubview:switchAccountBtn];
    [self.contenView addSubview:self.bottomView];
}

#pragma mark == 切换账号
- (void)switchAccountBtnAction{
    
    [JBWAlertView  showSwitchAccount:nil suerBlcok:^{
        [self.parentViewController dismissViewControllerAnimated:NO completion:^{
            
            [[JBWSDKInstance sharedInstance] jbwLogin];
            
        }];
    }];
    
}

#pragma mark == UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 5;
}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        TJWBMeNameTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TJWBMeNameTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.row == 4){
        JBWMeVersionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JBWMeVersionTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        JBWMePassWordTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JBWMePassWordTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.row == 1) {
            cell.titleLabel.text = @"修改密码";

        }else if (indexPath.row == 2){
            cell.titleLabel.text = @"绑定手机";

        }else{
            cell.titleLabel.text = @"实名认证";

        }
        return cell;
    }
  
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row == 0) {
       return 80;
    }else if (indexPath.row == 4){
       return 80;
    }else{
        return 40;
    }
    
   
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        [self.navigationController pushViewController:[JBWReviseNameViewController new] animated:NO];

    }else if (indexPath.row ==1){
        
      [self.navigationController pushViewController:[JBWRevisePassWordViewController new] animated:NO];

    }else if (indexPath.row ==2){
        
        [self.navigationController pushViewController:[JBWBindingPhoneViewController new] animated:NO];
        
    }else if (indexPath.row ==3){
        
        [self.navigationController pushViewController:[JBWRealNameAuthenticationViewController new] animated:NO];
        
    }else if (indexPath.row ==4){
        
     
        
    }
    
}
@end
